/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.businessLayer;

import mnstudent.dataacesslayer.InfoSemesterYearDAL;
import mnstudent.datatranferobject.InfoSemesterYearDTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 11520_000
 */
public class InfoSemesterYearBLL {
    
    private InfoSemesterYearDAL m_InfoSemesterYearDAL;
    
    public InfoSemesterYearBLL()
    {
        m_InfoSemesterYearDAL = new InfoSemesterYearDAL();
    }
    
    //<editor-fold defaultstate="collapsed" desc=" Method ">
    public boolean checkInfoSemesterYearIsHaveInDatabase(String _idSemester, String _idYear)
    {
        boolean out = false;
        ResultSet rs = m_InfoSemesterYearDAL.checkInfoSemesterYearIsHaveInDatabase(_idSemester, _idYear);
        try {
            while(rs.next())
            {
                if(rs.getInt(1)>0)
                    out = false;
                else
                    out = true;
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return out;
    }
      /**
     * Ham lay tat ca cac khoa
     *
     * @return ResultSet
     */
    public ResultSet getAllInfoSemesterYear(){
        
      return m_InfoSemesterYearDAL.getAllInfoSemesterYear();
    }
    
    /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getInfoSemesterYearById(String _id)
    {
        
        return m_InfoSemesterYearDAL.getInfoSemesterYearById(_id);
    }
    
    public ArrayList<InfoSemesterYearDTO> getInfoSemesterYearByIdYear(String _idYear)
    {
        ArrayList<InfoSemesterYearDTO> temp = new ArrayList<>();
        ResultSet rs = m_InfoSemesterYearDAL.getInfoSemesterYearByIdYear(_idYear);
        try {
            while(rs.next())
            {
                InfoSemesterYearDTO obj = new InfoSemesterYearDTO(rs.getNString(1),
                        rs.getNString(2),
                        rs.getNString(3),
                        rs.getDate(4),
                        rs.getDate(5),
                        rs.getDate(6),
                        rs.getDate(7),
                        rs.getInt(8));
                temp.add(obj);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return temp;
    }
    
    public InfoSemesterYearDTO getInfoSemesterYearByIdSemesterAndIdYear(String _idSemester, String _idYear)
    {
        InfoSemesterYearDTO obj = null;
        ResultSet rs = m_InfoSemesterYearDAL.getInfoSemesterYearByIdSemesterAndIdYear(_idSemester, _idYear);
        try {
            while(rs.next())
            {
                obj = new InfoSemesterYearDTO(rs.getNString(1), rs.getNString(2), rs.getNString(3),
                rs.getDate(4), rs.getDate(5), rs.getDate(6), rs.getDate(7), rs.getInt(8));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return obj;
    }
     /**
     * ham them moi khoa xuong database
     * @param _infoSemesterYear
     * @return true: success, false: fail
     */
    public boolean insertInfoSemesterYearToDatabase(InfoSemesterYearDTO _infoSemesterYear)
    {
        
      return m_InfoSemesterYearDAL.insertInfoSemesterYearToDatabase(_infoSemesterYear);
    }
    
    /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _infoSemesterYear
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateInfoSemesterYearToDatabase(InfoSemesterYearDTO _infoSemesterYear)
    {
      
        return m_InfoSemesterYearDAL.updateInfoSemesterYearToDatabase(_infoSemesterYear);
    }
    
    /**
     * Ham xoa mot khoa ra khoi database
     * @param _infoSemesterYear
     * @return 
     */
     public boolean deleteInfoSemesterYearFromDatabase(String _infoSemesterYearID)
    {
        
        return m_InfoSemesterYearDAL.deleteInfoSemesterYearFromDatabase(_infoSemesterYearID);
    }
    //</editor-fold>
}
